export DEBIAN_FRONTEND="noninteractive"

<% if !@apt[:multiarch].nil? && (@apt[:multiarch] == false) -%>
rm -fv /etc/dpkg/dpkg.cfg.d/multiarch || true
<% end -%>

apt-get -qy update
apt-get -qy install apt-transport-https

<% if !@apt[:sources].nil? && @apt[:sources].count > 0 -%>
rm -fv /etc/apt/sources.list || true
<% @apt[:sources].flatten.compact.each do |source| -%>
echo '<%= source %>' | tee -a /etc/apt/sources.list
<% end -%>
apt-get -qy update
<% end -%>

<% if !@apt[:install].nil? -%>
<% @apt[:install].flatten.compact.each do |package| -%>
dpkg --status <%= package %> &> /dev/null || apt-get -qy install <%= package %>
<% end -%>
<% end -%>

<% if !@apt[:remove].nil? -%>
<% @apt[:remove].flatten.compact.each do |package| -%>
dpkg --status <%= package %> &> /dev/null && apt-get -qy remove <%= package %>
<% end -%>
<% end -%>

<% if !@apt[:purge].nil? -%>
<% @apt[:purge].flatten.compact.each do |package| -%>
dpkg --status <%= package %> &> /dev/null && apt-get -qy purge <%= package %>
<% end -%>
<% end -%>
